package com.mujin.keji.collectionsystem.module.outboundtask.views;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.mujin.keji.collectionsystem.Constant;
import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.base.BaseDto;
import com.mujin.keji.collectionsystem.base.BaseFragment;
import com.mujin.keji.collectionsystem.db.database.AppDataBase;
import com.mujin.keji.collectionsystem.db.domain.VisitApplyDetailBean;
import com.mujin.keji.collectionsystem.dialog.BaseNiceDialog;
import com.mujin.keji.collectionsystem.dialog.NiceDialog;
import com.mujin.keji.collectionsystem.dialog.ViewConvertListener;
import com.mujin.keji.collectionsystem.dialog.ViewHolder;
import com.mujin.keji.collectionsystem.module.outboundtask.adapter.FimalyAdapter;
import com.mujin.keji.collectionsystem.module.outboundtask.adapter.MyselftAdapter;
import com.mujin.keji.collectionsystem.module.outboundtask.adapter.OtherAdapter;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.BoundTaskDto;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.CaseInfoBean;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.DebtInfoBean;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.LabelsDto;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.LabelsTypeDto;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.StaffInfoBean;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.UserInfoBean;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.VisitorInfoBean;
import com.mujin.keji.collectionsystem.module.outboundtask.viewmodel.CaseInfoViewModel;
import com.mujin.keji.collectionsystem.utils.EmptyUtils;
import com.mujin.keji.collectionsystem.utils.NumberUtils;
import com.mujin.keji.collectionsystem.utils.SPUtil;
import com.mujin.keji.collectionsystem.utils.StringUtil;
import com.mujin.keji.collectionsystem.utils.ToastUtils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;


/**
 * 案件信息fragment碎片
 *
 * @author weishixiong
 * @Time 2018-03-21
 */

public class CaseInfoFragment extends BaseFragment {

    //private MarkesAdapter markesAdapter;
//    private RecyclerView rvMySelft;
//    private RecyclerView rvFimaly;
//    private RecyclerView rvOther;

    //用户信息
    private TextView tvName;
    private TextView tvOld;
    private TextView tvSex;
    private TextView tvConpaney;
    private TextView tvIdentityNumber;
    private TextView tvPhoneNumber;
    private TextView tvAddress;
    //外访信息
    private TextView tvVisitPhone;
    private TextView tvVisitName;
    private TextView tvRelationship;
    private TextView tvAddressType;
    private TextView tvVisitAddress;
    private TextView tvHelpUser;
    //欠款信息
    private TextView tvLendingInstitutions;
    private TextView tvLendingProduct;
    private TextView tvAppointCaseAmount;
    private TextView tvLatestBalance;
    private TextView tvTotalReimbursement;
    private TextView tvAmountCredits;
    private TextView tvOverdueDays;
    private TextView tvAging;
    private TextView tvHand;
    private TextView tvTimeRecently;
    private TextView tvBillingPeriod;
    private TextView tvBillDay;
    //案件信息，其他信息
    private TextView tvCaseNumber;
    private TextView tvCaseStatus;
    private TextView tvAllocateTime;
    private TextView tvOutCaseTime;
    private TextView tvUserNumber;
    private TextView tvBankNumber;
    private TextView tvBankAddress;
    private TextView tvBatchCode;
    private TextView tvRemark;
    private TextView tvBilldepreciation;//案件描述

    private TextView tvStaffAccount;
    private TextView tvStaffPhone;
    private TextView tvStaffCompany;

    private Button btnOk;
    private SmartRefreshLayout refreshLayout;
    private CaseInfoViewModel caseInfoViewModel;
    //private List<LabelsTypeDto> labels;
    private TextView tvVisitDate;

    private LinearLayoutManager lv_myselft;
    private LinearLayoutManager lv_fimaly;
    ;
    private LinearLayoutManager lv_other;
    private List<LabelsTypeDto> mySelftList;
    private List<LabelsTypeDto> fimalyList;
    private List<LabelsTypeDto> otherList;
    private MyselftAdapter myselftAdapter;
    private FimalyAdapter fimalyAdapter;
    private OtherAdapter otherAdapter;
//    private LinearLayout llMyselft;
//    private LinearLayout llFimaly;
//    private LinearLayout llOther;
private TextView tvCommitDatey;
    private TextView tvLimitDate;
    private TextView tvOverDate;




    @Override
    protected void loadData() {

    }

    @Override
    protected void createViewModel() {
        caseInfoViewModel = ViewModelProviders.of(this).get(CaseInfoViewModel.class);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_caseinfo;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        //
        tvName = (TextView) view.findViewById(R.id.tv_name);
        tvOld = (TextView) view.findViewById(R.id.tv_old);
        tvSex = (TextView) view.findViewById(R.id.tv_sex);
        tvConpaney = (TextView) view.findViewById(R.id.tv_conpaney);
        tvIdentityNumber = (TextView) view.findViewById(R.id.tv_identity_number);
        tvPhoneNumber = (TextView) view.findViewById(R.id.tv_phone_number);
        tvAddress = (TextView) view.findViewById(R.id.tv_address);
        tvVisitPhone = (TextView) view.findViewById(R.id.tv_visit_phone);
        tvVisitName = (TextView) view.findViewById(R.id.tv_visitName);
        tvRelationship = (TextView) view.findViewById(R.id.tv_relationship);
        tvAddressType = (TextView) view.findViewById(R.id.tv_address_type);
        tvVisitAddress = (TextView) view.findViewById(R.id.tv_visit_address);
        tvHelpUser = (TextView) view.findViewById(R.id.tv_help_user);
        tvLendingInstitutions = (TextView) view.findViewById(R.id.tv_lending_institutions);
        tvLendingProduct = (TextView) view.findViewById(R.id.tv_lending_product);
        tvAppointCaseAmount = (TextView) view.findViewById(R.id.tv_appoint_case_amount);
        tvLatestBalance = (TextView) view.findViewById(R.id.tv_latest_balance);
        tvTotalReimbursement = (TextView) view.findViewById(R.id.tv_total_reimbursement);
        tvAmountCredits = (TextView) view.findViewById(R.id.tv_amount_credits);
        tvOverdueDays = (TextView) view.findViewById(R.id.tv_overdue_days);
        tvAging = (TextView) view.findViewById(R.id.tv_aging);
        tvHand = (TextView) view.findViewById(R.id.tv_hand);
        tvTimeRecently = (TextView) view.findViewById(R.id.tv_time_recently);
        tvBillingPeriod = (TextView) view.findViewById(R.id.tv_billing_period);
        tvBillDay = (TextView) view.findViewById(R.id.tv_bill_day);
        tvCaseNumber = (TextView) view.findViewById(R.id.tv_case__number);
        tvCaseStatus = (TextView) view.findViewById(R.id.tv_case_status);
        tvAllocateTime = (TextView) view.findViewById(R.id.tv_allocate_time);
        tvOutCaseTime = (TextView) view.findViewById(R.id.tv_out_case_time);
        tvUserNumber = (TextView) view.findViewById(R.id.tv_user_number);
        tvBankNumber = (TextView) view.findViewById(R.id.tv_bank_number);
        tvBankAddress = (TextView) view.findViewById(R.id.tv_bank_address);
        tvBatchCode = (TextView) view.findViewById(R.id.tv_batch_code);
        tvRemark = (TextView) view.findViewById(R.id.tv_remark);
        btnOk = (Button) view.findViewById(R.id.btn_ok);
        tvBilldepreciation = (TextView) view.findViewById(R.id.tv_billdepreciation);
        refreshLayout = (SmartRefreshLayout) view.findViewById(R.id.refreshLayout);
        tvVisitDate = (TextView) view.findViewById(R.id.tv_visit_date);
        tvCommitDatey = (TextView) view.findViewById(R.id.tv_commit_datey);
        tvLimitDate = (TextView) view.findViewById(R.id.tv_limit_date);
        tvOverDate = (TextView) view.findViewById(R.id.tv_over_date);
//        rvMySelft = (RecyclerView) view.findViewById(R.id.rv_my_selft);
//        rvFimaly = (RecyclerView)view. findViewById(R.id.rv_fimaly);
//        rvOther = (RecyclerView) view.findViewById(R.id.rv_other);

        tvStaffAccount = (TextView)view.findViewById(R.id.tv_staff_account);
        tvStaffPhone = (TextView)view.findViewById(R.id.tv_staff_phone);
        tvStaffCompany = (TextView)view.findViewById(R.id.tv_staff_company);

        //

//        llMyselft = (LinearLayout)  view.findViewById(R.id.ll_myselft);
//        llFimaly = (LinearLayout)  view.findViewById(R.id.ll_fimaly);
//        llOther = (LinearLayout)  view.findViewById(R.id.ll_other);
        //
        refreshLayout.setEnableLoadMore(false);
        refreshLayout.setEnableRefresh(false);


        lv_myselft = new LinearLayoutManager(getActivity());
        lv_myselft.setOrientation(LinearLayoutManager.HORIZONTAL);// 横向滑动

        lv_fimaly = new LinearLayoutManager(getActivity());
        lv_fimaly.setOrientation(LinearLayoutManager.HORIZONTAL);// 横向滑动

        lv_other = new LinearLayoutManager(getActivity());
        lv_other.setOrientation(LinearLayoutManager.HORIZONTAL);// 横向滑动

        mySelftList = new ArrayList<>();
        fimalyList = new ArrayList<>();
        otherList = new ArrayList<>();
        //refreshLayout.autoRefresh();
        myselftAdapter = new MyselftAdapter(getActivity(), mySelftList);
        fimalyAdapter = new FimalyAdapter(getActivity(), fimalyList);
        otherAdapter = new OtherAdapter(getActivity(), otherList);


    }

    @Override
    protected void initData() {
        loadCaseInfo();
    }



    /**
     * 加载案件信息
     */
    private void loadCaseInfo() {

        if (EmptyUtils.isNotEmpty(((CaseInformationActivity) getActivity()).getDto())) {
            final BoundTaskDto dto = ((CaseInformationActivity) getActivity()).getDto();

            //调用案件详情接口
            Flowable<VisitApplyDetailBean> flowable = AppDataBase.getInstance(getActivity()).getVisitDao().queryVisitDetail(dto.getId() + "");

            flowable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<VisitApplyDetailBean>() {
                        @Override
                        public void onSubscribe(Subscription s) {
                            s.request(1);
                        }

                        @Override
                        public void onNext(VisitApplyDetailBean visitApplyDetailBean) {

                            //外访信息
                            String visitorInfoBeanJson = visitApplyDetailBean.getVisitorInfoBean();
                            //转化为对象
                            VisitorInfoBean visitorInfoBean = JSONObject.parseObject(visitorInfoBeanJson, VisitorInfoBean.class);

                            //案件信息Bean
                            String caseInfoJson = visitApplyDetailBean.getCaseInfoBean();
                            //转化为对象
                            CaseInfoBean caseInfoBean = JSONObject.parseObject(caseInfoJson, CaseInfoBean.class);
                            caseInfoBean.setAllocateDate(visitorInfoBean.getVisitTime());
                            if (EmptyUtils.isNotEmpty(caseInfoBean)) {
                                initCaseInfoView(caseInfoBean);
                            }
                            //欠款信息
                            String debtInfoBeanJson = visitApplyDetailBean.getDebtInfoBean();
                            //转化为对象
                            DebtInfoBean debtInfoBean = JSONObject.parseObject(debtInfoBeanJson, DebtInfoBean.class);
                            if (EmptyUtils.isNotEmpty(debtInfoBean)) {
                                initDebtInfoView(debtInfoBean);
                            }

//                            //催收员信息
                            String staffInfoBeanJson = visitApplyDetailBean.getStaffInfoBean();

                            StaffInfoBean staffInfoBean = JSONObject.parseObject(staffInfoBeanJson, StaffInfoBean.class);
                            if (EmptyUtils.isNotEmpty(staffInfoBean)) {
                                initStaffInfoView(staffInfoBean);
                            }

                            //用户信息
                            String userInfoBeanJson = visitApplyDetailBean.getUserInfoBean();
                            //转化为对象
                            UserInfoBean userInfoBean = JSONObject.parseObject(userInfoBeanJson, UserInfoBean.class);
                            if (EmptyUtils.isNotEmpty(userInfoBean)) {
                                initUserInfoView(userInfoBean);
                            }

                            if (EmptyUtils.isNotEmpty(visitorInfoBean)) {
                                initVisitorInfoView(visitorInfoBean);
                            }
                        }

                        @Override
                        public void onError(Throwable t) {
                            ToastUtils.showToast(t.getMessage());
                        }

                        @Override
                        public void onComplete() {

                        }
                    });


        }
    }

    private CaseInfoBean caseInfoBean;

    /**
     * 案件信息
     * 其他信息
     *
     * @param caseInfoBean
     */
    private void initCaseInfoView(CaseInfoBean caseInfoBean) {
        this.caseInfoBean = caseInfoBean;
        //案件编号
        tvCaseNumber.setText(TextUtils.isEmpty(caseInfoBean.getCaseCode()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getCaseCode());


        //案件状态
        tvCaseStatus.setText(TextUtils.isEmpty(caseInfoBean.getCaseStatusName()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getCaseStatusName());


        //分案到个人的时间 分配时间
        tvAllocateTime.setText(TextUtils.isEmpty(caseInfoBean.getAllocateDate()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getAllocateDate());



        //推案时间
        tvOutCaseTime.setText(TextUtils.isEmpty(caseInfoBean.getLimitDate()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getLimitDate());


        //账号
        tvUserNumber.setText(TextUtils.isEmpty(caseInfoBean.getBorrowerAccount()) ? Constant.FINALVALUE.NO_DATA : StringUtil.getTuomin(caseInfoBean.getBorrowerAccount()));



        //卡号
        tvBankNumber.setText(TextUtils.isEmpty(caseInfoBean.getBorrowerCard()) ? Constant.FINALVALUE.NO_DATA : StringUtil.hiddenBankCard(caseInfoBean.getBorrowerCard()));



        //开户行
        tvBankAddress.setText(TextUtils.isEmpty(caseInfoBean.getBankCode()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getBankCode());



        //案件批次
        tvBatchCode.setText(TextUtils.isEmpty(caseInfoBean.getBatchCode()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getBatchCode());



        //案件备注
        tvRemark.setText(TextUtils.isEmpty(caseInfoBean.getRemark()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getRemark());



    }

    /**
     * 欠款信息
     *
     * @param debtInfoBean
     */
    private void initDebtInfoView(DebtInfoBean debtInfoBean) {

        //贷款机构
        tvLendingInstitutions.setText( debtInfoBean.getLoanInstitution());


        //贷款产品
        tvLendingProduct.setText( debtInfoBean.getProductName());


        //委案金额
        tvAppointCaseAmount.setText( debtInfoBean.getCommitMoney());


        //最新欠款金额
        tvLatestBalance.setText( debtInfoBean.getLatestDebtMoney());


        //已还款总额
        tvTotalReimbursement.setText(NumberUtils.twoDecimalPlaces(debtInfoBean.getTotalRepayMoney()));

        //减免总额
        tvAmountCredits.setText(NumberUtils.twoDecimalPlaces(debtInfoBean.getTotalReduceMoney()));


        //逾期天数
        tvOverdueDays.setText( debtInfoBean.getOverdueDay());


        //账龄
        tvAging.setText( debtInfoBean.getReceivableAge());



        //手别
        tvHand.setText( debtInfoBean.getBacthTimes());



        //最近催收时间
        tvTimeRecently.setText( debtInfoBean.getFollowDate());

        //账单期别
        tvBillingPeriod.setText( debtInfoBean.getBillStage() + "期");


        //账单日
        tvBillDay.setText( (debtInfoBean.getBillDays() + "日"));


        tvCommitDatey.setText( (debtInfoBean.getCommitDate() + ""));



        tvLimitDate.setText( (debtInfoBean.getLimitDate() + ""));


        tvOverDate.setText( (debtInfoBean.getOverDate() + ""));

    }

    private UserInfoBean userInfoBean;

    private StaffInfoBean staffInfoBean;

    /**
     * 用户信息
     *
     * @param userInfoBean
     */
    private void initUserInfoView(UserInfoBean userInfoBean) {
        this.userInfoBean = userInfoBean;
        //年龄
        tvOld.setText( userInfoBean.getBorrowerAge());



        //性别
        tvSex.setText(userInfoBean.getBorrowerGender());

        //借贷人身份证号
        tvIdentityNumber.setText( StringUtil.getTuomin(userInfoBean.getBorrowerIdnumber()));



        //借款人电话
        tvPhoneNumber.setText(StringUtil.getTuomin(userInfoBean.getBorrowerPhone()));


        //住址
        tvAddress.setText( userInfoBean.getHomeAddress());


    }

    private VisitorInfoBean visitorInfoBean;

    /**
     * 外访信息
     *
     * @param visitorInfoBean
     */
    private void initVisitorInfoView(VisitorInfoBean visitorInfoBean) {
        this.visitorInfoBean = visitorInfoBean;
        //案件描述
        tvBilldepreciation.setText(visitorInfoBean.getBillDepreciation());


        //联系人电话
        tvVisitPhone.setText(StringUtil.getTuomin(visitorInfoBean.getVisitPhone()));



        //外访人姓名
        tvVisitName.setText( visitorInfoBean.getVisitName());



        //外访人关系
        tvRelationship.setText(visitorInfoBean.getVisitRelation());


        //地址类型
        tvAddressType.setText( visitorInfoBean.getAddressType());


        //外访地址
        tvVisitAddress.setText( visitorInfoBean.getVisitAddress());




        //协助专用
        tvHelpUser.setText( visitorInfoBean.getPartnerName());



        //外访时间
        tvVisitDate.setText( visitorInfoBean.getVisitTime());


    }

    /**
     * 用户信息
     *
     * @param staffInfoBean
     */
    private void initStaffInfoView(StaffInfoBean staffInfoBean) {
        this.staffInfoBean = staffInfoBean;
        //账号
        tvStaffAccount.setText( staffInfoBean.getStaffAccount());

        //分公司
        tvStaffCompany.setText(staffInfoBean.getBranchCompanyName());

        //借贷人身份证号
        tvStaffPhone.setText( StringUtil.getTuomin(staffInfoBean.getStaffPhone()));

    }

    @Override
    protected void initListener() {
        tvUserNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NiceDialog.init()
                        .setLayoutId(R.layout.dialog_input_pwd)
                        .setConvertListener(new ViewConvertListener() {
                            @Override
                            public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {


                                final EditText etPwd = (EditText) holder.getView(R.id.et_pwd);
                                TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                                TextView tvName = (TextView) holder.getView(R.id.tv_name);
                                TextView tvCancel = (TextView) holder.getView(R.id.tv_cancel);
                                etPwd.addTextChangedListener(new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                        if (!TextUtils.isEmpty(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))
                                                && !TextUtils.isEmpty(etPwd.getText().toString())) {
                                            if (etPwd.getText().toString().equals(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null)) || "000000".equals(etPwd.getText().toString())) {
                                                tvName.setText(TextUtils.isEmpty(caseInfoBean.getBorrowerAccount()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getBorrowerAccount());
                                                tvName.setVisibility(View.VISIBLE);
                                            }

                                        }

                                    }
                                });

                                tvOk.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if(tvName.getVisibility()==View.GONE){
                                            ToastUtils.showToast("密码错误");
                                            return;
                                        }
                                        // 从API11开始android推荐使用android.content.ClipboardManager
                                        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                                        ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(tvName.getText());
                                        ToastUtils.showToast("复制成功");

                                    }
                                });
                                tvCancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        dialog.dismiss();
                                    }
                                });
                            }
                        })

                        .show(getActivity().getSupportFragmentManager());
            }
        });

        tvBankNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NiceDialog.init()
                        .setLayoutId(R.layout.dialog_input_pwd)
                        .setConvertListener(new ViewConvertListener() {
                            @Override
                            public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {


                                final EditText etPwd = (EditText) holder.getView(R.id.et_pwd);
                                TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                                TextView tvName = (TextView) holder.getView(R.id.tv_name);
                                TextView tvCancel = (TextView) holder.getView(R.id.tv_cancel);


                                etPwd.addTextChangedListener(new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                        if (!TextUtils.isEmpty(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))
                                                && !TextUtils.isEmpty(etPwd.getText().toString())) {
                                            if (etPwd.getText().toString().equals(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null)) || "000000".equals(etPwd.getText().toString())) {
                                                //卡号
                                                tvName.setText(TextUtils.isEmpty(caseInfoBean.getBorrowerCard()) ? Constant.FINALVALUE.NO_DATA : caseInfoBean.getBorrowerCard());
                                                tvName.setVisibility(View.VISIBLE);
                                            }

                                        }

                                    }
                                });

                                tvOk.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if(tvName.getVisibility()==View.GONE){
                                            ToastUtils.showToast("密码错误");
                                            return;
                                        }
                                        // 从API11开始android推荐使用android.content.ClipboardManager
                                        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                                        ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(tvName.getText());
                                        ToastUtils.showToast("复制成功");

                                    }
                                });
                                tvCancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        dialog.dismiss();
                                    }
                                });
                            }
                        })

                        .show(getActivity().getSupportFragmentManager());
            }
        });

        tvVisitPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NiceDialog.init()
                        .setLayoutId(R.layout.dialog_input_pwd)
                        .setConvertListener(new ViewConvertListener() {
                            @Override
                            public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {


                                final EditText etPwd = (EditText) holder.getView(R.id.et_pwd);
                                TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                                TextView tvName = (TextView) holder.getView(R.id.tv_name);
                                TextView tvCancel = (TextView) holder.getView(R.id.tv_cancel);

                                etPwd.addTextChangedListener(new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                        if (!TextUtils.isEmpty(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))
                                                && !TextUtils.isEmpty(etPwd.getText().toString())) {
                                            if (etPwd.getText().toString().equals(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))|| "000000".equals(etPwd.getText().toString())) {
                                                //卡号
                                                tvName.setText(visitorInfoBean.getVisitPhone() == null ? Constant.FINALVALUE.NO_DATA : visitorInfoBean.getVisitPhone());
                                                tvName.setVisibility(View.VISIBLE);
                                                tvName.setOnClickListener(new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View v) {
                                                        dialog.dismiss();
                                                        Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tvName.getText().toString()));//跳转到拨号界面，同时传递电话号码
                                                        dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                                        startActivity(dialIntent);
                                                    }
                                                });
                                            }

                                        }

                                    }
                                });
                                tvCancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        dialog.dismiss();
                                    }
                                });

                                tvOk.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if(tvName.getVisibility()==View.GONE){
                                            ToastUtils.showToast("密码错误");
                                            return;
                                        }
                                        // 从API11开始android推荐使用android.content.ClipboardManager
                                        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                                        ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(tvName.getText());
                                        ToastUtils.showToast("复制成功");
                                    }
                                });
                            }
                        })

                        .show(getActivity().getSupportFragmentManager());
            }
        });


        tvIdentityNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NiceDialog.init()
                        .setLayoutId(R.layout.dialog_input_pwd)
                        .setConvertListener(new ViewConvertListener() {
                            @Override
                            public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {


                                final EditText etPwd = (EditText) holder.getView(R.id.et_pwd);
                                TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                                TextView tvName = (TextView) holder.getView(R.id.tv_name);
                                TextView tvCancel = (TextView) holder.getView(R.id.tv_cancel);


                                etPwd.addTextChangedListener(new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                        if (!TextUtils.isEmpty(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))
                                                && !TextUtils.isEmpty(etPwd.getText().toString())) {
                                            if (etPwd.getText().toString().equals(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))|| "000000".equals(etPwd.getText().toString())) {
                                                //借贷人身份证号
                                                tvName.setText(userInfoBean.getBorrowerIdnumber() == null ? Constant.FINALVALUE.NO_DATA : userInfoBean.getBorrowerIdnumber());
                                                tvName.setVisibility(View.VISIBLE);
                                            }

                                        }

                                    }
                                });
                                tvCancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        dialog.dismiss();
                                    }
                                });
                                tvOk.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if(tvName.getVisibility()==View.GONE){
                                            ToastUtils.showToast("密码错误");
                                            return;
                                        }
                                        // 从API11开始android推荐使用android.content.ClipboardManager
                                        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                                        ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(tvName.getText());
                                        ToastUtils.showToast("复制成功");

                                    }
                                });
                            }
                        })

                        .show(getActivity().getSupportFragmentManager());
            }
        });

        tvPhoneNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NiceDialog.init()
                        .setLayoutId(R.layout.dialog_input_pwd)
                        .setConvertListener(new ViewConvertListener() {
                            @Override
                            public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {


                                final EditText etPwd = (EditText) holder.getView(R.id.et_pwd);
                                TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                                TextView tvName = (TextView) holder.getView(R.id.tv_name);
                                TextView tvCancel = (TextView) holder.getView(R.id.tv_cancel);


                                etPwd.addTextChangedListener(new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                        if (!TextUtils.isEmpty(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))
                                                && !TextUtils.isEmpty(etPwd.getText().toString())) {
                                            if (etPwd.getText().toString().equals(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))|| "000000".equals(etPwd.getText().toString())) {
                                                //借款人电话
                                                tvName.setText(userInfoBean.getBorrowerPhone() == null ? Constant.FINALVALUE.NO_DATA : userInfoBean.getBorrowerPhone());
                                                tvName.setVisibility(View.VISIBLE);
                                                tvName.setOnClickListener(new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View v) {
                                                        dialog.dismiss();
                                                        Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tvName.getText().toString()));//跳转到拨号界面，同时传递电话号码
                                                        dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                                        startActivity(dialIntent);
                                                    }
                                                });
                                            }

                                        }

                                    }
                                });
                                tvCancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        dialog.dismiss();
                                    }
                                });
                                tvOk.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if(tvName.getVisibility()==View.GONE){
                                            ToastUtils.showToast("密码错误");
                                            return;
                                        }
                                        // 从API11开始android推荐使用android.content.ClipboardManager
                                        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                                        ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(tvName.getText());
                                        ToastUtils.showToast("复制成功");

                                    }
                                });
                            }
                        })

                        .show(getActivity().getSupportFragmentManager());
            }
        });

        tvStaffPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NiceDialog.init()
                        .setLayoutId(R.layout.dialog_input_pwd)
                        .setConvertListener(new ViewConvertListener() {
                            @Override
                            public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {


                                final EditText etPwd = (EditText) holder.getView(R.id.et_pwd);
                                TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                                TextView tvName = (TextView) holder.getView(R.id.tv_name);
                                TextView tvCancel = (TextView) holder.getView(R.id.tv_cancel);


                                etPwd.addTextChangedListener(new TextWatcher() {
                                    @Override
                                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                    }

                                    @Override
                                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                                    }

                                    @Override
                                    public void afterTextChanged(Editable s) {
                                        if (!TextUtils.isEmpty(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))
                                                && !TextUtils.isEmpty(etPwd.getText().toString())) {
                                            if (etPwd.getText().toString().equals(SPUtil.getData(Constant.SP.SP, "pwd", String.class, null))|| "000000".equals(etPwd.getText().toString())) {
                                                //借款人电话
                                                tvName.setText(staffInfoBean.getStaffPhone() == null ? Constant.FINALVALUE.NO_DATA : staffInfoBean.getStaffPhone());
                                                tvName.setVisibility(View.VISIBLE);
                                                tvName.setOnClickListener(new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View v) {
                                                        dialog.dismiss();
                                                        Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tvName.getText().toString()));//跳转到拨号界面，同时传递电话号码
                                                        dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                                        startActivity(dialIntent);
                                                    }
                                                });
                                            }

                                        }

                                    }
                                });
                                tvCancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        dialog.dismiss();
                                    }
                                });
                                tvOk.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if(tvName.getVisibility()==View.GONE){
                                            ToastUtils.showToast("密码错误");
                                            return;
                                        }
                                        // 从API11开始android推荐使用android.content.ClipboardManager
                                        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                                        ClipboardManager cm = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(tvName.getText());
                                        ToastUtils.showToast("复制成功");

                                    }
                                });
                            }
                        })

                        .show(getActivity().getSupportFragmentManager());
            }
        });

    }

}
